#/bin/bash

# 添加pg_stat_statement的配置到配置文件
CONF=/var/lib/postgresql/data/postgresql.conf
echo "# postgresql.conf" | cat >> $CONF
echo "shared_preload_libraries = 'pg_stat_statements' " |cat >> $CONF
echo "pg_stat_statements.max = 10000" |cat >> $CONF
echo "pg_stat_statements.track = all“" |cat >> $CONF

#加该插件后需要重启服务器
/usr/lib/postgresql/10/bin/pg_ctl restart 

#加载sql文件
#/usr/share/postgresql/10/extension/pg_stat_statements--1.2--1.3.sql
#/usr/share/postgresql/10/extension/pg_stat_statements--1.4.sql
#/usr/share/postgresql/10/extension/pg_stat_statements--1.0--1.1.sql
#/usr/share/postgresql/10/extension/pg_stat_statements--unpackaged--1.0.sql
#/usr/share/postgresql/10/extension/pg_stat_statements--1.4--1.5.sql
#/usr/share/postgresql/10/extension/pg_stat_statements.control
#/usr/share/postgresql/10/extension/pg_stat_statements--1.1--1.2.sql
#/usr/share/postgresql/10/extension/pg_stat_statements--1.3--1.4.sql
/usr/bin/psql -f /usr/share/postgresql/10/extension/pg_stat_statements--1.4.sql

#创建stat_statements扩展视图
/usr/bin/psql --c 'create extension pg_stat_statements';
